<?php
header("Content-type:text/html; charset=utf-8");

class Mysql{
	private $mysql,$result,$result_array_one,$result_array_all,$row;
	function __construct(){
		$this->mysql=new PDO("mysql:host=localhost;dbname=ruiyou_info","root","root");
		$this->result_array_one=array();
		$this->result_array_all=array();
		$this->mysql->query("set names utf8");
	}
	
	function getJudge(){
		$select=$this->mysql->prepare("select * from judge_item order by date desc");
		$select->execute();
		while($row=$select->fetch(PDO::FETCH_ASSOC)){
			$this->result_array_one['gamename']=$row['gamename'];
			$this->result_array_one['version']=$row['version'];
			$this->result_array_one['date']=$row['date'];
			$this->result_array_one['executor']=$row['executor'];
			$this->result_array_one['result']=$row['result'];
			$this->result_array_one['operater']=$row['operater'];
			$this->result_array_one['detail']=$row['detail'];
			$this->result_array_one['wordsrc']=$row['wordsrc'];
			
			array_push($this->result_array_all,$this->result_array_one);
		}
		
		return $this->result_array_all;
		$this->result_array_all=array();
	}
	
	function addJudge($gamename,$version,$date,$executor,$result,$operater,$detail,$wordsrc){
		$insert=$this->mysql->prepare("insert into judge_item(gamename,version,date,executor,result,operater,detail,wordsrc) values ('$gamename','$version','$date','$executor','$result','$operater','$detail','$wordsrc')");
		$status=$insert->execute();
		
		if($status){
			return 1;
		}else {
			return 0;
		}
	}
	
	function getSelectJudge($keyword){
		$select=$this->mysql->prepare("select * from judge_item where gamename like '%$keyword%' or date like '%keyword%' or version like '%$keyword%' order by date desc");
		$select->execute();
		while($row=$select->fetch(PDO::FETCH_ASSOC)){
			$this->result_array_one['gamename']=$row['gamename'];
			$this->result_array_one['version']=$row['version'];
			$this->result_array_one['date']=$row['date'];
			$this->result_array_one['executor']=$row['executor'];
			$this->result_array_one['result']=$row['result'];
			$this->result_array_one['operater']=$row['operater'];
			$this->result_array_one['detail']=$row['detail'];
			$this->result_array_one['wordsrc']=$row['wordsrc'];
			
			array_push($this->result_array_all,$this->result_array_one);
		}
		
		return $this->result_array_all;
		$this->result_array_all=array();
	}
	
	function __destruct(){
		$this->mysql=NULL;
	}
}

function alert($string){
	echo "<script language='javascript'>";
	echo "alert('$string');";
	echo "</script>";
}

function open($string,$string2){
	echo "<script language='javascript'>";
	echo "window.open('$string','$string2');";
	echo "</script>";
}

?>